package com.leanyuan.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leanyuan.domain.StaffMsg;
import com.leanyuan.publi.domain.HousDept;
import com.leanyuan.publi.service.HousDeptService;
import com.leanyuan.service.StaffMsgService_V;
import com.leanyuan.vo.DeptandEmpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 相亲相爱一家人
 * @since 2021-05-25
 */
@RestController
@RequestMapping("/leanyuan/staff-msg")
public class StaffMsgController {
    @Autowired
    StaffMsgService_V staffMsgServiceV;

    @Autowired
    HousDeptService housDeptService;

    //分页查询（员工信息、部门信息、录入人的连接查询）
    @RequestMapping("selectStaffMsgPage")
    public IPage<DeptandEmpVo> selectStaffMsgPage(Integer page,Integer pageSize,Model model){
        IPage<DeptandEmpVo> iPage=new Page<DeptandEmpVo>(page,pageSize);
        IPage<DeptandEmpVo> deptandEmpVoIPage=this.staffMsgServiceV.findByPage(iPage);
        model.addAttribute("deptandEmpVoIPage",deptandEmpVoIPage);
        return deptandEmpVoIPage;
    }

    //查询所有部门信息
    @RequestMapping("selectDept")
    public List<HousDept> selecDept(){
        return this.housDeptService.list(null);
    }

    //添加员工信息
    @RequestMapping("addEmp")
    public boolean addEmp(@RequestBody StaffMsg staffMsg){
        staffMsg.setAddtime(new Date());
        return this.staffMsgServiceV.save(staffMsg);
    }

    //根据ID删除员工信息
    @RequestMapping( "deleteEmpById")
    public boolean deleteEmpById(Integer id){
        return this.staffMsgServiceV.removeById(id);
    }

    //根据Id修改信息
    @RequestMapping("updateEmpById")
    public boolean updateEmpById(@RequestBody StaffMsg staffMsg){
        return this.staffMsgServiceV.updateById(staffMsg);
    }

    //带条件的分页查询（员工信息、部门信息、录入人的连接查询）
    @RequestMapping("selectStaffMsgPageByParam")
    public IPage<DeptandEmpVo> selectStaffMsgPageByParam(Integer deptid,Integer empid,String empname,Integer page,Integer pageSize,Model model){
        IPage<DeptandEmpVo> iPage=new Page<DeptandEmpVo>(page,pageSize);
        IPage<DeptandEmpVo> deptandEmpVo=this.staffMsgServiceV.findPageByParam(iPage,deptid,empid,empname);
        model.addAttribute("deptandEmpVo",deptandEmpVo);
        return deptandEmpVo;
    }
}

